<?php
include_once("../../_inc/config.php");
include_once("../../_class/db.php");
header('Content-type:text/javascript;charset=UTF-8');
session_start();
$sql = new db();
$json = json_decode(stripslashes($_POST["_gt_json"]));
$idcom = $json->{'parameters'}->{'idcom'};
$req = "SELECT li.Numero_ligne, col.Id_colis, pa.Id_palette,  col.description,  li.Quantite FROM palette AS pa, preparation AS pr, ligne_commande AS li, colis_type AS col WHERE li.Id_Commande =".$idcom." AND col.Id_colis = li.Id_colis AND pr.Id_Commande =".$idcom." AND pr.Id_Ordre_preparation = pa.Id_Ordre_preparation GROUP BY li.Numero_ligne";
$sql->query($req);
$retArray = array();
if ($sql->num_rows() <= 0)
{
	$req = "SELECT li.Numero_ligne, col.Id_colis, pa.Id_palette,  col.description,  li.Quantite FROM palette AS pa, ligne_commande AS li, colis_type AS col WHERE li.Id_Commande =".$idcom." AND col.Id_colis = li.Id_colis GROUP BY li.Numero_ligne";
	$sql->query($req);
	while ($row = $sql->fetch_row()) 
	{
		$row[2] = "n/a";
		$retArray[] = $row;
	}
}
else
{
while ($row = $sql->fetch_row())
	{
		$retArray[] = $row;
	}
}
$data = json_encode($retArray);
$ret = "{data:" . $data .",\n";
$ret .= "recordType : 'array'}";
echo $ret;
?>